#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 4010;
const int M = 6e4+10;
const int inf = 0x3f3f3f3f;

int n,m,s,t,cnt=1,h[N],u[M],d[N],dfn[N],low[N],tim,bel[N],nodenum,now[N],stk[N],top;
bool vis[N];
struct edge{int v,w,nxt;}e[M<<1];
void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;e[++cnt] = (edge){x,0,h[y]};h[y] = cnt;}

bool bfs(){
	queue<int> q; q.push(s); memset(d,0,sizeof(d)); d[s] = 1; now[s] = h[s];
	while(q.size()){
		int x = q.front(); q.pop();
		for(int i = h[x],y;i;i = e[i].nxt){
			if(e[i].w && !d[y = e[i].v]){
				d[y] = d[x] + 1; now[y] = h[y];
				q.push(y); if(y == t) return 1;
			}
		}
	}return 0;
}

int dfs(int x,int flow){
	if(x == t) return flow;
	int res = flow;
	for(int i = now[x],y;i&&res;i = e[i].nxt){
		now[x] = i;
		if(d[y = e[i].v] == d[x] + 1 && e[i].w){
			int k = dfs(y,min(res,e[i].w));
			if(!k) d[y] = 0; res -= k; e[i].w -= k;e[i^1].w += k;
		}
	}return flow - res;
}

void dfs(int x){
	low[x] = dfn[x] = ++tim; vis[x] = 1;stk[++top] = x;
	for(int i = h[x],y;i;i = e[i].nxt){
		if(e[i].w){
			if(!dfn[y = e[i].v]) dfs(y),low[x] = min(low[x],low[y]);
			else if(vis[y]) low[x] = min(low[x],dfn[y]);
		}
	}
	if(dfn[x] == low[x]){
		int y; ++nodenum;
		do{
			y = stk[top--]; bel[y] = nodenum; vis[y] = 0; 
		}while(y != x);
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in,s = in,t = in;
	for(int i = 1,v,w;i <= m;i++){
		u[i] = in,v = in,w = in;
		link(u[i],v,w);
	}
	int flow = 0;
	while(bfs()) while(flow = dfs(s,inf));
	for(int i = 1;i <= n;i++) if(!dfn[i]) dfs(i);
	for(int i = 1;i <= m;i++){
		if(!e[i<<1].w){
			int x = u[i],y = e[i<<1].v;
			printf("%d %d\n",bel[x] != bel[y],bel[x] == bel[s] && bel[y] == bel[t]);
		}else puts("0 0");
	}
	return 0;
}

